<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算属性</title>
    <!-- 引用vue.js库 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
    <div id="app">
        <p>原数据：{{message}}</p>
        <p>反转之后的数据：{{reversedMessage}}</p>
        <button @click="add()">这是一个按钮</button>
        <div>计算总价:{{price}}</div>
    </div>
    <script>
        let vm = new Vue({
            // 根据id获取到容器div
            el:"#app",
            // data表示数据
            data:{
              message:"abcdefg",  
              package:{
                  count:5,
                  price:5
              }
            },
            methods:{
                add:function() {
                   this.package.count++
                }
            },
            computed: {
              reversedMessage:function() {
                return  this.message.split('').reverse().join('');
              },
              price:function() {
                  return this.package.count*this.package.price;
              }
            }
        });
    </script>
    
</body>
</html>